#include <vector>
using namespace std;
class Solution
{
public:
    int maxProfit(vector<int> &prices)
    {
        int ans = 0;
        int buy = prices[0];
        int length = prices.size();
        for (int i = 0; i < length; i++)
        {
            if (prices[i] > buy)
            {
                ans += prices[i] - buy;
            }
            buy = prices[i];
        }
        return ans;
    }
};